<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="档案编号" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入档案编号" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="档案标题" prop="title">
                <el-input v-model="queryParams.title" placeholder="请输入档案标题" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="副标题" prop="subTitle">
                <el-input v-model="queryParams.subTitle" placeholder="请输入档案副标题" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="档案分类" prop="groupId">
                <el-input v-model="queryParams.groupId" placeholder="请输入档案分类" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="流程状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择流程状态" clearable>
                    <el-option v-for="dict in dict.type.oa_flow_billstatus" :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
            </el-form-item>
            <el-form-item label="借阅状态" prop="brStatus">
                <el-select v-model="queryParams.brStatus" placeholder="请选择借阅状态" clearable>
                    <el-option v-for="dict in dict.type.archive_borrow_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
            </el-form-item>
            <el-form-item label="档案柜" prop="cabinetId">
                <el-input v-model="queryParams.cabinetId" placeholder="请输入档案柜" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="文件夹" prop="folderId">
                <el-input v-model="queryParams.folderId" placeholder="请输入文件夹" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <TableCard>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['am:amArchive:add']">新增</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['am:amArchive:export']">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table :border="Global.tableShowBorder" v-loading="loading" :data="amArchiveList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center"/>
                <el-table-column label="档案编号" align="center" prop="code" width="150"/>
                <el-table-column label="文件名称" align="center" prop="title" :show-overflow-tooltip="true"/>
                <el-table-column label="档案分类" align="center" prop="groupId" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <el-tag v-for="item in (scope.row.groupId?scope.row.groupId.split(','):[])">{{groupListMap[item]}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="借阅状态" align="center" prop="brStatus" width="150">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.archive_borrow_status" :value="scope.row.brStatus"/>
                    </template>
                </el-table-column>
                <el-table-column label="是否可用" align="center" prop="available" width="150">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.available"/>
                    </template>
                </el-table-column>

<!--                <el-table-column label="提交时间" align="center" prop="submitTime" width="180">-->
<!--                    <template slot-scope="scope">-->
<!--                        <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>-->
<!--                    </template>-->
<!--                </el-table-column>-->
<!--                <el-table-column label="备注" align="center" prop="remark"/>-->
                <el-table-column label="流程状态" align="center" prop="status" width="150">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.oa_flow_billstatus" :value="scope.row.status"/>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" v-show="scope.row.status=='0' || scope.row.status=='3'"  icon="el-icon-check" @click="doSubmitFlow(scope.row)" v-hasPermi="['oa:dutyApply:edit']">提交审批</el-button>
                            <el-button size="mini" type="text" v-show="scope.row.status=='0' || scope.row.status=='3'"  icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['oa:dutyApply:edit']">修改</el-button>
                            <el-button size="mini" type="text" v-show="scope.row.status=='0' || scope.row.status=='3'"  icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['oa:dutyApply:remove']">删除</el-button>

                            <el-button size="mini" type="text" v-show="scope.row.status=='1'"  icon="el-icon-refresh-right" @click="doCancleFlow(scope.row)" v-hasPermi="['oa:dutyApply:edit']" style="color: #ff6666">撤销申请</el-button>
                            <el-button size="mini" type="text" v-show="scope.row.status!='0'"  icon="el-icon-rank"          @click="flowDetail(scope.row)" v-hasPermi="['oa:dutyApply:edit']">流程信息</el-button>
                            <el-button size="mini" type="text" v-show="scope.row.status!='0'"  icon="el-icon-view"          @click="handleView(scope.row)" v-hasPermi="['oa:dutyApply:edit']">查看</el-button>
                        </template>
                </el-table-column>
            </el-table>

            <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
        </TableCard>

<!--        <FlowInfo :businessId="businessId" :billType="billType" v-if="showFlowInfo" :showStatus="showFlowInfo" @closeFlowInfoDialog="closeFlowInfoDialog"></FlowInfo>-->
    </div>
</template>

<script>
import {listAmArchive, getAmArchive, delAmArchive, addAmArchive, updateAmArchive} from "@/api/am/amArchive";
//import {cancleFlow, submitFlow} from "@/api/oa/processInstance";
//import FlowInfo from "@/views/oa/flow/flowInfo";
import {listAllAmGroup} from "@/api/am/amGroup";
export default {
    name: "AmArchive",
    //components:{FlowInfo},
    dicts: ['archive_borrow_status', 'oa_flow_billstatus', 'sys_normal_disable'],
    data() {
        return {
            billType: this.BillType.billType.ARCHIVE_UPLOAD,
            groupListMap:{},
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 档案文件表格数据
            amArchiveList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                code: '',
                title: null,
                subTitle: null,
                groupId: null,
                url: null,
                status: null,
                brStatus: null,
                available: null,
                cabinetId: null,
                folderId: null,
                userId: null,
                deptId: null,
                flowKey: null,
                flowInsId: null,
                submitTime: null,
            },
            showFlowInfo:false,
            businessId:null
        };
    },
    created() {
        const billType = this.$route.query && this.$route.query.billType;
        console.log("单据类型："+billType)
        if(billType){
            this.queryParams.billType = billType;
            this.billType = billType;
        }
        // 获取分组集合
        this.getGroupList();
        this.getList();
    },
    methods: {
        // 获取分组集合
        getGroupList(){
          let that = this;
            listAllAmGroup().then(res=>{
                let arr = res.data;
                arr.forEach((item,index)=>{
                  if (!that.groupListMap) {
                    that.groupListMap = {};
                  }
                  that.groupListMap[item.id] = item.name;
                })
                console.log(this.groupListMap)
            })
        },
        /** 查询档案文件列表 */
        getList() {
            this.loading = true;
            listAmArchive(this.queryParams).then(response => {
                this.amArchiveList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.$router.push({path: "/am/amArchive/form/add/"+this.billType})
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            const id = row.id
            this.$router.push({path: "/am/amArchive/form/" + row.id});
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除档案文件编号为"' + ids + '"的数据项？').then(function () {
                return delAmArchive(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {
            });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('am/amArchive/export', {
                ...this.queryParams
            }, `amArchive_${new Date().getTime()}.xlsx`)
        },

        /** 查看单据详情 */
        handleView(row){
            this.$router.push({path: "/am/amArchive/form/" + row.id, query: {readonly:"1"}})
        },
        /** 提交审批 ***/
        doSubmitFlow(row){
            let data = {
                businessId:row.id,
                billType: this.BillType.billType.ARCHIVE_UPLOAD
            }
            this.$modal.confirm('确认要提交该单据进行审批吗？').then(function () {
                //return submitFlow(data);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("提交成功");
            }).catch(() => {
            });
        },
        /** 取回审批 ***/
        doCancleFlow(row){
            let data = {
                businessId:row.id,
                billType: this.BillType.billType.ARCHIVE_UPLOAD
            }
            this.$modal.confirm('确认要取回该协议审批吗？').then( ()=> {
                // cancleFlow(data).then(res=>{
                //     if(200==res.code){
                //         this.getList();
                //         this.$modal.msgSuccess("取回成功");
                //     }
                // });
            })
        },
        /** 流程信息 ***/
        flowDetail(row){
            this.businessId = row.id+"";
            this.showFlowInfo = true;
        },
        //关闭流程信息窗口
        closeFlowInfoDialog(){
            this.showFlowInfo = false;
        },
    }
};
</script>
